package cn.xuanxuanyuhua.crm.service.impl;


import cn.xuanxuanyuhua.crm.domain.CustomerTraceHistory;
import cn.xuanxuanyuhua.crm.domain.Employee;
import cn.xuanxuanyuhua.crm.mapper.CustomerTraceHistoryMapper;
import cn.xuanxuanyuhua.crm.query.CustomerTraceHistoryQueryObject;
import cn.xuanxuanyuhua.crm.service.ICustomerTraceHistoryService;
import cn.xuanxuanyuhua.crm.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerTraceHistoryServiceImpl implements ICustomerTraceHistoryService {
    @Autowired
    private CustomerTraceHistoryMapper customerTraceHistoryMapper;


    @Override
    public PageInfo query(CustomerTraceHistoryQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<CustomerTraceHistory> list = customerTraceHistoryMapper.queryForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(CustomerTraceHistory entity) {
        if (entity.getId() != null) {
            entity.setInputTime(new Date());
            customerTraceHistoryMapper.updateByPrimaryKey(entity);
        }else{
            Employee activeUser = UserContext.getActiveUser();
            entity.setInputTime(new Date());
            entity.setInputUser(activeUser);
            customerTraceHistoryMapper.insert(entity);
        }
    }
}
